from selenium.webdriver.common.by import By

from webAutomation import utils
from webAutomation.base.base_page import BasePage, BaseHandle


# 对象层
# 首页页面类
class OverviewOfElectricCabinetPage(BasePage):
    def __init__(self):
        # 继承父类
        super().__init__()
        # 新增电柜
        self.add_electric_cabinet = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[1]/div/div[8]/button"
        # 地区下拉列表
        self.area = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[1]/div/div/div/input"
        # 地区名
        self.area_name = By.XPATH, "/html/body/div[3]/div[1]/div[1]/ul/li[3]/span"
        # 站点名
        self.site_name = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[2]/div/div/input"
        # 详细地址
        self.address = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[3]/div/div/input"
        # 电柜编码
        self.cabinet_num = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[4]/div/div/input"
        # 启用状态列表
        self.enable_status_list = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[5]/div/div/div/input"
        # 启用状态
        self.enable_status = By.XPATH, "/html/body/div[4]/div[1]/div[1]/ul/li[1]"
        # 经度
        self.longitude = By.XPATH, "//*[@id='app']/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[6]/div/div/input"
        # 纬度
        self.latitude = By.XPATH, '//*[@id="app"]/section/section/main/div[1]/div/div/div[2]/div/div[2]/form/div[7]/div/div/input'
        # 确定新增
        self.assure_add = By.XPATH, '//*[@id="app"]/section/section/main/div[1]/div/div/div[2]/div/div[3]/div/button[2]/span'

    # 查找新增电柜按钮
    def find_add_electric_cabinet(self):
        return self.find_element(self.add_electric_cabinet)

    # 查找地区下拉列表
    def find_area_list(self):
        return self.find_element(self.area)

    # 查找地区名
    def find_area_name(self):
        return self.find_element(self.area_name)

    # 查找站点名
    def find_site_name(self):
        return self.find_element(self.site_name)

    # 查找详细地址
    def find_address(self):
        return self.find_element(self.address)

    # 查找电柜编码
    def find_cabinet_num(self):
        return self.find_element(self.cabinet_num)

    # 查找启用状态下拉列表
    def find_enable_status_list(self):
        return self.find_element(self.enable_status_list)

    # 查找启用状态
    def find_enable_status(self):
        return self.find_element(self.enable_status)

    # 查找经度
    def find_longitude(self):
        return self.find_element(self.longitude)

    # 查找纬度
    def find_latitude(self):
        return self.find_element(self.latitude)

    # 确定新增
    def find_assure_add(self):
        return self.find_element(self.assure_add)


# 操作层
class OverviewOfElectricCabinetHandle(BaseHandle):
    def __init__(self):
        # 实例化首页页面类
        self.overview_of_electric_cabinet_page = OverviewOfElectricCabinetPage()

    # 点击新增电柜按钮
    def click_add_electric_cabinet(self):
        return self.overview_of_electric_cabinet_page.find_add_electric_cabinet().click()

    # 点击地区下拉列表
    def click_area_list(self):
        return self.overview_of_electric_cabinet_page.find_area_list().click()

    # 选择地区名
    def click_area_name(self):
        return self.overview_of_electric_cabinet_page.find_area_name().click()

    # 输入站点名
    def input_site_name(self, site_name):
        return self.input_text(self.overview_of_electric_cabinet_page.find_site_name(), site_name)

    # 输入详细地址
    def input_address(self, address):
        return self.input_text(self.overview_of_electric_cabinet_page.find_address(), address)

    # 输入电柜编码
    def input_cabinet_num(self, cabinet_num):
        return self.input_text(self.overview_of_electric_cabinet_page.find_cabinet_num(), cabinet_num)

    # 点击启用状态下拉列表
    def click_enable_status_list(self):
        return self.overview_of_electric_cabinet_page.find_enable_status_list().click()

    # 点击启用状态
    def click_enable_status(self):
        return self.overview_of_electric_cabinet_page.find_enable_status().click()

    # 输入经度
    def input_longitude(self, longitude):
        return self.input_text(self.overview_of_electric_cabinet_page.find_longitude(), longitude)

    # 输入纬度
    def input_latitude(self, latitude):
        return self.input_text(self.overview_of_electric_cabinet_page.find_latitude(), latitude)

    # 确定新增
    def click_assure_add(self):
        return self.overview_of_electric_cabinet_page.find_assure_add().click()


# 业务层
class OverviewOfElectricCabinetProxy:
    def __init__(self):
        self.overview_of_electric_cabinet_handle = OverviewOfElectricCabinetHandle()

    def add_cabinet(self, site_name, address, cabinet_num, longitude, latitude):
        print("---------add_cabinet start...----------")
        # 点击新增电柜按钮
        self.overview_of_electric_cabinet_handle.click_add_electric_cabinet()
        # 选择地区
        self.overview_of_electric_cabinet_handle.click_area_list()
        # 选择地区名字
        self.overview_of_electric_cabinet_handle.click_area_name()
        # 输入站点名
        self.overview_of_electric_cabinet_handle.input_site_name(site_name)
        # 输入详细地址
        self.overview_of_electric_cabinet_handle.input_address(address)
        # 输入电柜编码
        self.overview_of_electric_cabinet_handle.input_cabinet_num(cabinet_num)
        # 点击启用状态下拉列表
        self.overview_of_electric_cabinet_handle.click_enable_status_list()
        # 点击启用状态
        self.overview_of_electric_cabinet_handle.click_enable_status()
        # 输入经度
        self.overview_of_electric_cabinet_handle.input_longitude(longitude)
        # 输入纬度
        self.overview_of_electric_cabinet_handle.input_latitude(latitude)
        # 确定新增
        self.overview_of_electric_cabinet_handle.click_assure_add()
        print("----------add cabinet end...-----------")
